package com.company.beauty.common.utils;

import java.util.concurrent.ScheduledThreadPoolExecutor;
import java.util.concurrent.ThreadFactory;

/**
 * <p>executors</p >
 *
 * @author youyoukele
 * @version 1.0
 * @date 2024/4/18 14:00
 */
public class Executors {

    /**
     * new scheduled thread pool
     *
     * @param corePoolSize
     * @param threadFactory
     * @return
     */
    public static ScheduledThreadPoolExecutor newScheduledThreadPool(int corePoolSize, ThreadFactory threadFactory) {
        return new ScheduledThreadPoolExecutor(corePoolSize, threadFactory);
    }

    /**
     * new scheduled thread pool
     *
     * @param corePoolSize
     * @param threadName
     * @return
     */
    public static ScheduledThreadPoolExecutor newScheduledThreadPool(int corePoolSize, String threadName) {
        return new ScheduledThreadPoolExecutor(corePoolSize, r -> {
            Thread t = new Thread(r);
            t.setName(threadName);
            t.setDaemon(true);
            return t;
        });
    }


}
